import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import '@/assets/scss/reset.scss'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import http from './api/config'
import './mock'



// router.beforeEach((to, from, next) => {
//   // 防止刷新后vuex里丢失token
//   store.commit('getToken')
//   // 防止刷新后vuex里丢失标签列表tagList
//   store.commit('getMenu')
//   let token = store.state.user.token
//   // 过滤登录页，防止死循环
//   if (!token && to.name !== 'login') {
//     next({ name: 'login' })
//   } else {
//     next()
//   }
// })

Vue.config.productionTip = false
Vue.prototype.$http = http
Vue.use(ElementUI)

router.beforeEach((to, from, next)=>{
  store.commit('getToken')
  let token = store.state.user.token
  if(!token && to.name !== 'login'){
    next({
      name:'login'
    })
  }else {
    next()
  }
})


new Vue({
  router,
  store,
  render: h => h(App),
  created() {
    console.log("vue被创建")
    console.log(router)
    store.commit('addMenu', router)
  }
}).$mount('#app')
